//
//  HsImageUtil.m
//  Hybrid-iPad
//
//  Created by Mead on 4/24/14.
//  Copyright (c) 2014 hundsun. All rights reserved.
//

#import "HsImageUtil.h"

@implementation HsImageUtil

+ (NSData*) imageFrom:(UIImage*)image scale:(CGFloat)scale compression:(CGFloat)compression;{
    CGSize newSize = CGSizeMake(image.size.width * scale, image.size.height * scale);
    UIGraphicsBeginImageContext(newSize);
    [image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
    UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    NSData *data =UIImageJPEGRepresentation(newImage, compression);
    return data;
}

+(UIImage*) createImageWithColor: (UIColor*) color{
    CGRect rect=CGRectMake(0.0f, 0.0f, 412.0, 44.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    //
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    //
    CGContextSetStrokeColorWithColor(context, [UIColor colorWithRed:0xca/255.0f green:0xca/255.0f blue:0xca/255.0f alpha:1.0f].CGColor);
    CGContextSetLineWidth(context, 1.0);
    CGContextMoveToPoint(context, 0, 0);
    CGContextAddLineToPoint(context, 412,0);
    
    CGContextSetStrokeColorWithColor(context, [UIColor colorWithRed:0xe2/255.0f green:0xe1/255.0f blue:0xe1/255.0f alpha:1.0f].CGColor);
    CGContextMoveToPoint(context, 0, 44);
    CGContextAddLineToPoint(context, 412,44);
    CGContextStrokePath(context);
    //
    UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return theImage;
}

@end
